package editor.modelo;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;


public class Space {

	public static  enum Tipo { 
		tr //transitable
		{ public String toString(){return "tr";}},
		of //oficina
		{ public String toString(){return "of";}},
		au //aula
		{ public String toString(){return "au";}},
		ot //piso
		{public String toString(){return "ot";}},
		pi //otro, como un baño o administrativos
		{public String toString(){return "pi";}}
		
	}

	protected Point2D centro;
	protected List<Point2D> borde;
	protected String id;
	protected String name;
	protected Tipo tipo;
	protected String nombrePadre;
	protected Integer height;
	
	protected int xmin, ymin, xmax, ymax;
	
	public Integer getHeight() {
		return height;
	}
	public void setHeight(Integer height) {
		this.height = height;
	}
	public void setNombrePadreCompleto(String nombre){
		this.nombrePadre = nombre;
	}
	public String getNombreCompleto(){
		return nombrePadre +"/"+ id;
	}

	public Space() {
		borde = new ArrayList<Point2D>();
		this.height= 0;
	}

	public Point2D getCentro() {
		return centro;
	}

	public void setCentro(Point2D.Float centro) {
		this.centro = centro;
	}

	public void setCentro(float x, float y) {
		this.centro = new Point2D.Float(x, y);
	
	}

	public List<Point2D> getBorde() {
		return borde;
	}
	
	public void setBorde(List<Point2D> list) {
		this.borde = list;
	}

	public String getId() {

		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	

	public Tipo getTipo() {
		return tipo;
	}

	public void setTipo(Tipo tipo) {
		this.tipo = tipo;
	}
	
	public Point2D getNextPoint(Point2D pto){
		int i = borde.indexOf(pto);
		if(i>= 0) return borde.get((i+1) % borde.size());
		else return null;
	}
	
	public Point2D getPrevPoint(Point2D pto) {
		int i = borde.indexOf(pto);
		if(i>= 0) return borde.get((i-1 + borde.size()) % borde.size());
		else return null;

	}

	
	public void calculateBoundingBox(){
		xmin = ymin = 50000;
		ymax =xmax = -50000;
		for(Point2D p: borde){
			xmin = Math.min(xmin,(int)p.getX());
			xmax = Math.max(xmax,(int)p.getX());
			ymin = Math.min(ymin,(int)p.getY());
			ymax = Math.max(ymax,(int)p.getY());
		}
	}
	
	public boolean contains(float x, float y){
		return (x>=xmin && x<=xmax && y >= ymin && y<=ymax);
	}

}